<template>
  <div style="height: 100%">
    <div id="deawer" style="padding:4px">

      <div>
        <p v-tit="$t('ex.differenceInfo')"></p>
        <info :inputData="routeData" style="padding:10px"></info>
      </div>
      <div>
        <p v-tit="$t('ex.invSernumInventory')"></p>
        <v-detailList ref="detailList"></v-detailList>
      </div>
      <div style="border:1px solid #ddd">
        <p v-tit="$t('ex.differenceCheck')"></p>
        <el-form ref="form" :model="routeData" inline label-width="80px"  style="padding:10px">
          <el-form-item :label="$t('ex.reviewRemark')" prop="reviewRemark"  style="width:90%">
            <el-input type="textarea" v-model="routeData.reviewRemark" inline="false" ></el-input>
          </el-form-item>
          <br/>
          <el-form-item :label="$t('ex.reviewUser')" prop="reviewUser">
            <el-input v-model="routeData.reviewUser" disabled></el-input>
          </el-form-item>
          <el-form-item :label="$t('ex.reviewTime')" prop="reviewTime">
            <el-date-picker v-model="routeData.reviewTime" disabled type="date"> </el-date-picker>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <!-- <v-tableTitle
        :btnConfig="btnConfig"
        @cancel="cancel"
        @check="check"
        @differenceAdjustCheck="differenceAdjustCheck"
    ></v-tableTitle> -->
    <div class="footer">
        <el-button v-for="btn in btnConfig" :key="btn.invalid" @click="emit(btn)">{{ btn.label }}</el-button>
    </div>
  </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import tableTitle from "commons/TableTitle";
import detail from "../details/Detail"
import detailList from "../detailsList/DetailList"
import info from "../details/page/info.vue"

export default {
  name: "",
  mixins: [baseMixin, skipMixin],
  data () {
    return {
      newFlag: false,
      routeData: {},
      dataList: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('ex.check'), certigier: !this.btnPermNameList.includes('WM06021203'), invalid: "check" },
        { label: this.$t('ex.differenceAdjustCheck'), certigier: !this.btnPermNameList.includes('WM06021204'), invalid: "differenceAdjustCheck" },
        { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM06021205'), invalid: "cancel" },
      ]
    }
  },
  created () {
  },
  methods: {
    emit(btn){
      this[btn.invalid]()
    },
    //复核按钮
    async check() {
      try {
        this.routeData.reviewMode ='14201'; // 手工复核
        this.routeData.serialDiffStatus ='13702';// 已复核
        let res = await this.$api.post(`/invSernumInventoryDifference/updateInvSernumInventoryDifference`,this.routeData);
        
          this.$message.success(res.returnMgr);
          this.cancel();
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    differenceAdjustCheck(){
      //跳转到调整界面
      this.$store.commit('setNewFlag',true);
      this.$store.commit("setRouteData", this.routeData);
      this.$router.push({ name: "adjustmentDeawer"});
    },
    //弹框取消
    cancel () {
      let routerName = JSON.parse(sessionStorage.getItem('routerName'));
      let num = -1;
      if (routerName) {
        num = routerName.indexOf("invSernumInventoryDifference");
      }
      if (num === -1) {
        this.$router.push({ name: "invSernumInventoryDifference" });
      } else {
        num = num - 0;
        routerName.splice(num, 1);
        sessionStorage.setItem('routerName', JSON.stringify(routerName));
        this.$router.push({ name: "home1" })
      }
    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.routeData = data.routeData;
      this.newFlag = data.newFlag;
    } else {
      this.routeData = this.$store.state.routeData;
      this.newFlag = this.$store.state.newFlag;
    }
    this.routeData.reviewUser = this.$Cookies.get('user');
    this.routeData.reviewTime = new Date();
    console.log(this.routeData);
  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-detail": detail,
    "v-detailList": detailList,
    info
  },
  beforeDestroy () {
    let routerName = JSON.parse(sessionStorage.getItem('routerName'));
    let num = -1;
    if (routerName) {
      num = routerName.indexOf("invSernumInventoryDifference");
    }
    if (num === -1) {
    } else {
      num = num - 0;
      routerName.splice(num, 1);
      sessionStorage.setItem('routerName', JSON.stringify(routerName));
    }
  }
}
</script>

<style lang="scss" scoped>
#deawer{
  &>div{
    border: 1px solid #ddd;
    border-bottom: 0;
  }
  h5{
    line-height: 1.8em;
    background: #eff3f7;
    padding-left: 10px;
    margin: 0;
  }
}
.footer{
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  padding: 10px 0;
  background: #f1f1f1;
}
</style>
